package com.niodata.dp.collection;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

public class WrappedStringKeyMap extends HashMap<String, Object> implements Serializable {

  public WrappedStringKeyMap() {
  }

  public WrappedStringKeyMap(Map<String, String> map) {
    super.putAll(map);
  }

  public static WrappedStringKeyMap load(Properties properties) {
    WrappedStringKeyMap map = new WrappedStringKeyMap();
    for (Object key : properties.keySet()) {
      map.put(key.toString(), properties.getProperty(key.toString()));
    }
    return map;
  }

  public String getString(String key) {
    return super.get(key) != null ? super.get(key).toString() : null;
  }

  public String getString(String key, String defaultValue) {
    return super.containsKey(key) ? getString(key) : defaultValue;
  }

  public Integer getInteger(String key, Integer defaultValue) {
    return super.containsKey(key) ? getInteger(key) : defaultValue;
  }

  public Integer getInteger(String key) {
    return super.get(key) != null ? Integer.valueOf(super.get(key).toString()) : null;
  }

  public Boolean getBoolean(String key, Boolean defaultValue) {
    return super.containsKey(key) ? getBoolean(key) : defaultValue;
  }

  public Boolean getBoolean(String key) {
    return super.get(key) != null ? Boolean.valueOf(super.get(key).toString()) : null;
  }

  public Long getLong(String key, Long defaultValue) {
    return super.containsKey(key) ? getLong(key) : defaultValue;
  }

  public Long getLong(String key) {
    return super.get(key) != null ? Long.valueOf(super.get(key).toString()) : null;
  }

  public Float getFloat(String key, Float defaultValue) {
    return super.containsKey(key) ? getFloat(key) : defaultValue;
  }

  public Float getFloat(String key) {
    return super.get(key) != null ? Float.valueOf(super.get(key).toString()) : null;
  }

  public Double getDouble(String key, Double defaultValue) {
    return super.containsKey(key) ? getDouble(key) : defaultValue;
  }

  public Double getDouble(String key) {
    return super.get(key) != null ? Double.valueOf(super.get(key).toString()) : null;
  }
}
